<html>
<head><meta charset="utf-8"><title>Resolving methods · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Resolving.20methods.html">Resolving methods</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221366093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Resolving%20methods/near/221366093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Phil Ellison <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Resolving.20methods.html#221366093">(Jan 01 2021 at 19:55)</a>:</h4>
<p>I'm not sure how to address this comment: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/7062/files#r550238723">https://github.com/rust-analyzer/rust-analyzer/pull/7062/files#r550238723</a>. Could someone please point me in the right direction. I can use self.infer.method_resolution to get hold of a FunctionId for the method being called (e.g. filter_map) and Resolver::resolve_known_trait to get hold of a TraitId for std::iter::Iterator, but I'm not sure what I can do to relate the two (i.e. how to conclude that this FunctionId is for a method on the iterator trait identified by TraitId).</p>



<a name="221366722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Resolving%20methods/near/221366722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Resolving.20methods.html#221366722">(Jan 01 2021 at 20:10)</a>:</h4>
<p>with the <code>FunctionId</code>, you can do <code>id.lookup(db.upcast()).container</code> to get the container, which you can then check whether it's equal to <code>AssocContainerId::TraitId(iterator_trait_id)</code> to see whether it's a method from Iterator</p>



<a name="221366819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Resolving%20methods/near/221366819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Resolving.20methods.html#221366819">(Jan 01 2021 at 20:13)</a>:</h4>
<p>I wish there was a more straightforward way to do that in the HIR crates (in code_model, it's easier)</p>



<a name="221366976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Resolving%20methods/near/221366976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Phil Ellison <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Resolving.20methods.html#221366976">(Jan 01 2021 at 20:16)</a>:</h4>
<p>Thanks! I'll give this a go.</p>



<a name="221367405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Resolving%20methods/near/221367405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Resolving.20methods.html#221367405">(Jan 01 2021 at 20:28)</a>:</h4>
<p>alternatively, you could do <code>db.trait_data(trait_id).items.get(name![filter_map])</code> to get the method by name</p>



<a name="221367615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Resolving%20methods/near/221367615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Phil Ellison <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Resolving.20methods.html#221367615">(Jan 01 2021 at 20:34)</a>:</h4>
<p>Perfect, thanks.</p>



<a name="221369139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Resolving%20methods/near/221369139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Phil Ellison <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Resolving.20methods.html#221369139">(Jan 01 2021 at 21:13)</a>:</h4>
<p>This turned out to be surprisingly easy! <a href="https://github.com/rust-analyzer/rust-analyzer/pull/7062/commits/b667328e74859dd1b5c1dd9a48c97f5f58277d3c">https://github.com/rust-analyzer/rust-analyzer/pull/7062/commits/b667328e74859dd1b5c1dd9a48c97f5f58277d3c</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>